using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading;

namespace ns20
{
	internal class Class184<T> : IEnumerable<T>, ICollection<T>, IEnumerable, IList, ICollection, Interface15
	{
		private readonly IList ilist_0;

		private readonly ICollection<T> icollection_0;

		private object object_0;

		public virtual int Count
		{
			get
			{
				if (icollection_0 != null)
				{
					return icollection_0.Count;
				}
				return ilist_0.Count;
			}
		}

		public virtual bool IsReadOnly
		{
			get
			{
				if (icollection_0 != null)
				{
					return icollection_0.IsReadOnly;
				}
				return ilist_0.IsReadOnly;
			}
		}

		bool IList.IsFixedSize
		{
			get
			{
				if (icollection_0 != null)
				{
					return icollection_0.IsReadOnly;
				}
				return ilist_0.IsFixedSize;
			}
		}

		object IList.this[int index]
		{
			get
			{
				if (icollection_0 != null)
				{
					throw new InvalidOperationException("Wrapped ICollection<T> does not support indexer.");
				}
				return ilist_0[index];
			}
			set
			{
				if (icollection_0 != null)
				{
					throw new InvalidOperationException("Wrapped ICollection<T> does not support indexer.");
				}
				smethod_0(value);
				ilist_0[index] = (T)value;
			}
		}

		bool ICollection.IsSynchronized => false;

		object ICollection.SyncRoot
		{
			get
			{
				if (object_0 == null)
				{
					Interlocked.CompareExchange(ref object_0, new object(), null);
				}
				return object_0;
			}
		}

		public object Object_0
		{
			get
			{
				if (icollection_0 != null)
				{
					return icollection_0;
				}
				return ilist_0;
			}
		}

		public Class184(IList list)
		{
			Class204.smethod_2(list, "list");
			if (list is ICollection<T>)
			{
				icollection_0 = (ICollection<T>)list;
			}
			else
			{
				ilist_0 = list;
			}
		}

		public Class184(ICollection<T> list)
		{
			Class204.smethod_2(list, "list");
			icollection_0 = list;
		}

		public virtual void Add(T item)
		{
			if (icollection_0 != null)
			{
				icollection_0.Add(item);
			}
			else
			{
				ilist_0.Add(item);
			}
		}

		public virtual void Clear()
		{
			if (icollection_0 != null)
			{
				icollection_0.Clear();
			}
			else
			{
				ilist_0.Clear();
			}
		}

		public virtual bool Contains(T item)
		{
			if (icollection_0 != null)
			{
				return icollection_0.Contains(item);
			}
			return ilist_0.Contains(item);
		}

		public virtual void CopyTo(T[] array, int arrayIndex)
		{
			if (icollection_0 != null)
			{
				icollection_0.CopyTo(array, arrayIndex);
			}
			else
			{
				ilist_0.CopyTo(array, arrayIndex);
			}
		}

		public virtual bool Remove(T item)
		{
			if (icollection_0 != null)
			{
				return icollection_0.Remove(item);
			}
			bool result;
			if (result = ilist_0.Contains(item))
			{
				ilist_0.Remove(item);
			}
			return result;
		}

		public virtual IEnumerator<T> GetEnumerator()
		{
			if (icollection_0 != null)
			{
				return icollection_0.GetEnumerator();
			}
			return ilist_0.Cast<T>().GetEnumerator();
		}

		IEnumerator IEnumerable.GetEnumerator()
		{
			if (icollection_0 != null)
			{
				return icollection_0.GetEnumerator();
			}
			return ilist_0.GetEnumerator();
		}

		int IList.Add(object value)
		{
			smethod_0(value);
			Add((T)value);
			return Count - 1;
		}

		bool IList.Contains(object value)
		{
			if (smethod_1(value))
			{
				return Contains((T)value);
			}
			return false;
		}

		int IList.IndexOf(object value)
		{
			if (icollection_0 != null)
			{
				throw new InvalidOperationException("Wrapped ICollection<T> does not support IndexOf.");
			}
			if (smethod_1(value))
			{
				return ilist_0.IndexOf((T)value);
			}
			return -1;
		}

		void IList.RemoveAt(int index)
		{
			if (icollection_0 != null)
			{
				throw new InvalidOperationException("Wrapped ICollection<T> does not support RemoveAt.");
			}
			ilist_0.RemoveAt(index);
		}

		void IList.Insert(int index, object value)
		{
			if (icollection_0 != null)
			{
				throw new InvalidOperationException("Wrapped ICollection<T> does not support Insert.");
			}
			smethod_0(value);
			ilist_0.Insert(index, (T)value);
		}

		void IList.Remove(object value)
		{
			if (smethod_1(value))
			{
				Remove((T)value);
			}
		}

		void ICollection.CopyTo(Array array, int arrayIndex)
		{
			CopyTo((T[])array, arrayIndex);
		}

		private static void smethod_0(object object_1)
		{
			if (!smethod_1(object_1))
			{
				throw new ArgumentException("The value '{0}' is not of type '{1}' and cannot be used in this generic collection.".smethod_1(CultureInfo.InvariantCulture, object_1, typeof(T)), "value");
			}
		}

		private static bool smethod_1(object object_1)
		{
			if (!(object_1 is T) && (object_1 != null || (typeof(T).smethod_12() && !Class195.smethod_10(typeof(T)))))
			{
				return false;
			}
			return true;
		}
	}
}
